package com.slaffka.model.notification;

import com.slaffka.model.NotificationType;
import com.slaffka.model.user.User;

import javax.persistence.*;
import java.io.Serializable;
import java.util.Collection;
import java.util.Date;

/**
 * Created by IntelliJ IDEA.
 * User: v.tsapaev
 * Date: 24.02.12
 * Time: 1:16
 * To change this template use File | Settings | File Templates.
 */
@Entity
@Table(name = "notification")
//@DiscriminatorColumn(name = "notification_type", discriminatorType = DiscriminatorType.STRING)
@Inheritance(strategy = InheritanceType.JOINED)
public class Notification implements Serializable {


    @Id
    @Column(name = "notification_id")
    @GeneratedValue(strategy = GenerationType.AUTO)
    protected Long notificationId;

    @ManyToMany(fetch = FetchType.EAGER)
    @JoinTable(
            name="notification_target",
            uniqueConstraints = {@UniqueConstraint(columnNames = {"notification_id", "user_id"})},
            joinColumns=@JoinColumn(name="notification_id"),
            inverseJoinColumns=@JoinColumn(name="user_id")
    )
    protected Collection<User> targetUsers;

    @Column(name = "notification_type")
    @Enumerated(EnumType.STRING)
    protected NotificationType notificationType;

    @ManyToOne
    @JoinColumn(name = "user_id")
    protected User owner;

    @Column(name = "date_start")
    protected Date createDate;

    public Long getNotificationId() {
        return notificationId;
    }

    public void setNotificationId(Long notificationId) {
        this.notificationId = notificationId;
    }

    public Collection<User> getTargetUsers() {
        if (targetUsers == null || targetUsers.isEmpty())
        {
            return null;
        }
        return targetUsers;
    }

    public void setTargetUsers(Collection<User> targetUsers) {
        this.targetUsers = targetUsers;
    }

    public NotificationType getNotificationType(){
        return notificationType;
    }

    public User getOwner() {
        return owner;
    }

    public void setOwner(User owner) {
        this.owner = owner;
    }

    public Date getCreateDate() {
        return createDate;
    }

    public void setCreateDate(Date createDate) {
        this.createDate = createDate;
    }

    //    @Override
//    public String toString() {
//        return "Notification{" +
//                "notificationId=" + notificationId +
//                ", targetUserSessions=" + targetUserSessions +
//                ", owner=" + owner +
//                '}';
//    }
}
